package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.util.KiteObjectUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.enums.InstType;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInstFunc;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import com.iwhalecloud.bss.kite.service.scene.attr.OperateInstAttrService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 流量周期用量限额
 */
public class FlowUseLimitAttrHandler extends AbstractAttrHandler<KiteProdInstFunc, AttrData> {
    @Autowired
    private OperateInstAttrService operateInstAttrService;
    @Autowired
    private IQuerySceneInstService querySceneInstService;

    @Override
    public void def(KiteAttr attr, KiteProdInstFunc inst, AttrData data) {
        //产品订购-NB产品-新增通讯计划，流量周期用量限额（M）需求规定当流量APN类型为NB时，自动填充为30M，目前不自动填充
        String custId = data.getCustId();
        KiteInst kiteInst = querySceneInstService
            .getKiteInst(custId, InstType.PROD_INST, inst.getAccProdInstId());
        if (!KiteObjectUtils.isEmpty(kiteInst)) {
            KiteAttr kiteAttr = kiteInst.getAttr("200003674");
            if (!KiteObjectUtils.isEmpty(kiteAttr)) {
                if (KiteStringUtils.equals("100006418", kiteAttr.getValue())) {
                    operateInstAttrService.setAttrValue(inst, attr.getFieldName(), "30", data.getSceneInstId(), null);
                }
            }
        }
    }
}
